import store from "@/store/idnex.js";
/**
 * 云函数调用封装
 */
async function cloudsAreEncapsulat(name, data, Loading) {
	if (!Loading) {
		uni.showLoading({
			title: '加载中....',
		})
	}
	let c1 = new wx.cloud.Cloud({
		// 资源方 AppID
		resourceAppid: getApp().globalData.resourceAppid,
		// 资源方环境 ID
		resourceEnv: getApp().globalData.resourceEnv,
	})
	await c1.init()
	return new Promise((resolve, reject) => {
		c1.callFunction({
			name,
			data
		}).then((res) => {
			if (!Loading) {
				uni.hideLoading()
			}
			resolve(res)
		})
	})
}

/**
 * 获取手机号
 * @param {Object} name
 * @param {Object} data
 */
async function getPhoneNumber(name, data) {
	uni.showLoading({
		title: '正在获取....',
	})
	let c1 = new wx.cloud.Cloud({
		// 资源方 AppID
		resourceAppid: getApp().globalData.resourceAppid,
		// 资源方环境 ID
		resourceEnv: getApp().globalData.resourceEnv,
	})
	await c1.init()
	let param = {
		weRunData: c1.CloudID(data),
	}
	return new Promise((resolve, reject) => {
		c1.callFunction({
			name,
			data: param
		}).then((res) => {
			uni.hideLoading()
			resolve(res)
		})
	})
}
export {
	cloudsAreEncapsulat,
	getPhoneNumber
};